<?php

namespace app\common\model\mysql;

use think\Model;

class OrderProductWater extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'or_order_product_water';

    /**
     * 查询订单售水数据列表
     * @param array $where
     * @param string $field
     * @return OrderProductWater[]|array|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getNormalOrderProductWater(array $where = [], string $field = "*"){
        $order = [
            "order_product_water_id" =>"asc",
        ];
        $result = $this->where($where)->field($field)->order($order)->select();
        return $result->toArray();
    }

    /**
     * 查询订单售水总量
     * @param array $where
     * @param string $field
     * @return float
     */
    public function getOrderProductWaterSum(array $where = [], string $field = "sellcount"){
        $result = $this->where($where)->sum($field);
        return $result;
    }

    /**
     * 根据where条件获取订单售水数据
     * @param array $where
     * @param string $field
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getOrderProductWaterFind(array $where = [], string $field = "*"){
        $result = $this->where($where)->field($field)->find();
        return $result ? $result->toArray() : [];
    }

    /**
     * 根据where条件更新数据表中的数据
     * @param $where
     * @param $data
     * @return bool
     */
    public function saveOrderProductWaterData($where,$data){
        if(empty($data) || !is_array($data)){
            return false;
        }
        return $this->where($where)->save($data);
    }
}
